<!DOCTYPE HTML>
<html lang="en">
<head>
<title>WinWaitActive / WinWaitNotActive - Syntax &amp; Usage | AutoHotkey</title>
<meta name="description" content="The WinWaitActive and WinWaitNotActive commands wait until the specified window is active or not active." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>WinWaitActive / WinWaitNotActive</h1>

<p>Waits until the specified window is active or not active.</p>

<pre class="Syntax">
<span class="func">WinWaitActive</span> <span class="optional">, WinTitle, WinText, Timeout, ExcludeTitle, ExcludeText</span>
<span class="func">WinWaitNotActive</span> <span class="optional">, WinTitle, WinText, Timeout, ExcludeTitle, ExcludeText</span>
</pre>
<h2>Parameters</h2>
<dl>

  <dt>WinTitle</dt>
  <dd><p>A window title or other criteria identifying the target window. See <a href="../misc/WinTitle.htm">WinTitle</a>.</p></dd>

  <dt>WinText</dt>
  <dd><p>If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if <a href="DetectHiddenText.htm">DetectHiddenText</a> is ON.</p></dd>

  <dt>Timeout</dt>
  <dd><p>How many seconds to wait before timing out and setting <a href="../misc/ErrorLevel.htm">ErrorLevel</a> to 1. Leave blank to allow the command to wait indefinitely.  Specifying 0 is the same as specifying 0.5. This parameter can be an <a href="../Variables.htm#Expressions">expression</a>.</p></dd>

  <dt>ExcludeTitle</dt>
  <dd><p>Windows whose titles include this value will not be considered.</p></dd>

  <dt>ExcludeText</dt>
  <dd><p>Windows whose text include this value will not be considered.</p></dd>

</dl>

<h2>ErrorLevel</h2>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if the command timed out or 0 otherwise.</p>
<h2>Remarks</h2>
<p>If a matching window satisfies the command's expectation, the command will not wait for <em>Timeout</em> to expire. Instead, it will immediately set <a href="../misc/ErrorLevel.htm">ErrorLevel</a> to 0 and the script will continue executing.</p>
<p>Both WinWaitActive and WinWaitNotActive will update the <a href="../misc/WinTitle.htm#LastFoundWindow">Last Found Window</a> if a qualified window is active when the command begins. In addition, WinWaitActive will update the Last Found Window if a qualified window becomes active before the command times out.</p>
<p>While the command is in a waiting state, new <a href="../misc/Threads.htm">threads</a> can be launched via <a href="../Hotkeys.htm">hotkey</a>, <a href="Menu.htm">custom menu item</a>, or <a href="SetTimer.htm">timer</a>.</p>
<p>If another <a href="../misc/Threads.htm">thread</a> changes the contents of any variable(s) that were used for this command's parameters, the command will not see the change -- it will continue to use the title and text that were originally present in the variables when the command first started waiting.</p>
<p>Window titles and text are case sensitive. Hidden windows are not detected unless <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> has been turned on.</p>
<h2>Related</h2>
<p><a href="WinWait.htm">WinWait</a>, <a href="WinWaitClose.htm">WinWaitClose</a>, <a href="WinExist.htm">WinExist() / IfWinExist</a>, <a href="WinActive.htm">WinActive() / IfWinActive</a>, <a href="SetTitleMatchMode.htm">SetTitleMatchMode</a>, <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a></p>
<h2>Examples</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>Run, notepad.exe
WinWaitActive, Untitled - Notepad, , 2
if ErrorLevel
{
    MsgBox, WinWait timed out.
    return
}
else
    WinMinimize  <em>; minimize the window found by WinWaitActive.</em></pre>
</div>

</body>
</html>
